package com.example.shop.service.impl;

import com.example.shop.entity.Role;
import com.example.shop.dao.RoleMapper;
import com.example.shop.service.RoleService;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

/**
 * (Role)表服务实现类
 *
 * @author makejava
 * @since 2025-03-26 09:28:38
 */
@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param roleid 主键
     * @return 实例对象
     */
    @Override
    public Role queryById(Integer roleid) {
        return this.roleMapper.queryById(roleid);
    }


    /**
     * 新增数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @Override
    public Role insert(Role role) {
        this.roleMapper.insert(role);
        return role;
    }

    /**
     * 修改数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @Override
    public Role update(Role role) {
        this.roleMapper.update(role);
        return this.queryById(role.getRoleid());
    }

    /**
     * 通过主键删除数据
     *
     * @param roleid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer roleid) {
        return this.roleMapper.deleteById(roleid) > 0;
    }
}
